<!--新增/修改地址-->
<style>


</style>
<template>
  <div>
    <group title="收货电话">
      <x-input novalidate :show-clear="true" v-model="recieverPhone" placeholder-align="right"></x-input>
    </group>
    <group title="收货人">
      <x-input novalidate :show-clear="true" v-model="recieverName" placeholder-align="right"></x-input>
    </group>
    <group title="地址">
      <x-input novalidate :show-clear="true" v-model="address" placeholder-align="right"></x-input>
    </group>
    <br/>
    <x-button type="primary" @click.native="save()">保存</x-button>
  </div>
</template>
<script>
import { XInput, Group, XButton, Cell } from 'vux'
export default {
  components: {
    XInput,
    Group,
    XButton,
    Cell
  },
  data() {
    return {
      userId: window.localStorage["userId"],
      addressId: this.$route.query.addressId,
      recieverPhone: '',
      recieverName: '',
      address: '',
      goodsId: this.$route.query.goodsId,
      goodsCount: this.$route.query.goodsCount
    }
  },
  mounted() {
    this.initAddress()
  },
  methods: {
    initAddress() {
      var _that = this
      if (_that.addressId != '') {
        _that.$tldAjax({
          isLayer: false,
          url: _that.$domain + "/tld/admin/address/getDetail.json",
          params: {
            userId: _that.userId,
            addressId: _that.addressId,
          },
          successFc: (response) => {
            _that.recieverPhone = response.data.data.recieverPhone
            _that.recieverName = response.data.data.recieverName
            _that.address = response.data.data.address
          }
        });
      }
    },
    save() {
      var _that = this
      this.$tldAjax({
        isLayer: false,
        url: this.$domain + "/tld/admin/address/save.json",
        params: {
          userId: this.userId,
          id: this.addressId,
          recieverPhone: this.recieverPhone,
          recieverName: this.recieverName,
          address: this.address
        },
        successFc: (response) => {
          _that.$router.push({
            path: '/tourl/addressList'
          })
        }
      });
    }
  }
}

</script>
